const app = getApp();
Page({
  data: {
    //用户个人信息
    hasAuthorize: app.globalData.hasAuthorize,
    userInfo: {
      id: 0,
      avatarUrl: "/images/user/niming.jpg",
      nickName: "点击登录",
      rdSession: ""
    },
    //下方条目
    myItems: [
      {
        typeId: 0,
        name: "我的地址",
        url: "",
        imageurl: "/images/my/address.png"
      },
      {
        typeId: 1,
        name: "联系方式",
        url: "",
        imageurl: "/images/my/phone.png"
      },
      {
        typeId: 2,
        name: "系统设置",
        url: "",
        imageurl: "/images/my/setting.png"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (app.globalData.userInfo) {
      that.setData({
        userInfo: app.globalData.userInfo,
        hasAuthorize: app.globalData.hasAuthorize
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 处理点击我的收藏事件
   */
  toCollection: function(){
    if (!(app.globalData.userInfo)) {
      wx.showModal({
        title: '请先登录',
        content: '',
      })
    }else{
      wx.navigateTo({
        url: '../../pages/my/myCollection/myCollection',
      })
    }
  },

  /**
   * 手动登录
   */

  /**
   * 用户点击发布后处理函数
   */
  toPublish: function(e){
    var that = that;
    if (!app.globalData.userInfo) {
      console.log(app.globalData.rdSession);
      wx.showModal({
        title: '请先登录',
        content: '',
        success:function(res){
        }
      })
    }else{
      wx.showActionSheet({
        itemList: ["发布二手商品", "发布寻物启事", "发布兼职信息"],
        itemColor: "#f5bf0d",
        success: function (res) {
          if (res.tapIndex == 0) {
            wx.navigateTo({
              url: '../goods/publishGoods/publishGoods',
            })
          } else if (res.tapIndex == 1) {
            wx.navigateTo({
              url: '../lost/lost_found/lost_found',
            })
          } else if (res.tapIndex == 2) {
            wx.navigateTo({
              url: '../parttime/publish/publish',
            })
          }
        },
        fail:function(res){
        }
      })
    }
  },

  /**
   * 处理点击发布记录事件
   */
  toRecord: function(){
    if (!app.globalData.userInfo) {
      wx.showModal({
        title: '请先登录',
        content: '',
      })
    }else{
      wx.navigateTo({
        url: '../../pages/my/myRecord/myRecord',
      })
    }
  },
  
  /**
   * 点击列表选项后跳转页面
   */
  toOther: function(e) {
    var id = e.currentTarget.id;
    if (!app.globalData.userInfo){
      wx.showModal({
        title: '请先登录',
        content: '',
      })
    }else{
      if (id == 0) {//跳转地址设置
        wx.navigateTo({
          url: '../../pages/my/myAdress/myAdress',
        })
      } else if (id == 1) {//跳转联系方式设置
        wx.navigateTo({
          url: '',
        })
      } else if (id == 2) {//跳转系统设置
        wx.navigateTo({
          url: '../../pages/my/setting/setting',
        })
      }
    }
  },

  // 设置背景颜色数据
  changeColor: function () {
    var bgColor = this.data.pageBackgroundColor == 'red' ? '#5cb85c' : 'red';
    this.setData({
      pageBackgroundColor: bgColor
    });
  },
  bindGetUserInfo: function (e) {
    var that = this;
    that.setData({
      userInfo: e.detail.userInfo
    });
    app.loginedToDo(app.updateUserInfo, e.detail.userInfo);
  },

})